# 图片人脸识别
import dlib
import cv2

# 加载人脸检测器
detector = dlib.get_frontal_face_detector()

# 读取图像
image = cv2.imread('./static/2.png')

# 转换为灰度图像
gray_image = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)

# 人脸检测
faces = detector(gray_image)

# 绘制人脸框
for face in faces:
    x, y, w, h = face.left(), face.top(), face.width(), face.height()
    cv2.rectangle(image, (x, y), (x + w, y + h), (0, 255, 0), 2)

# 显示图像
cv2.imshow('Face Detection', image)
cv2.waitKey(0)
cv2.destroyAllWindows()
